home *** CD-ROM | disk | FTP | other *** search
- int DissolveMain(HANDLE hStream, ImagePluginApplyParams *psParams,
- int r, int g, int b, int bCross)
- {
- int nSrcPercent, nLength, i;
- ImageSample *psSrcSample, *psDstSample;
- DWORD dwPos;
-
- nLength = psParams->dwWidth*psParams->dwHeight;
-
- // if reverse dir, change the frame pos appropriately.
- dwPos = psParams->dwPos;
- dwPos = psParams->dwFrames-1-psParams->dwPos;
-
- if (bCross)
- {
- // cross dissolve.
-
- int bAlphaZero = 0;
- nSrcPercent = 0;
- if (psParams->dwFrames > 1)
- nSrcPercent = (dwPos*256)/(psParams->dwFrames-1);
-
- if (!psParams->bBelow)
- {
- nSrcPercent = 256-nSrcPercent;
- }
- // double the slope and clip it at 256.
- // (draw the graph and see, you'll understand)
- nSrcPercent *= 2;
- if (nSrcPercent > 256)
- {
- nSrcPercent = 256;
- if (psParams->bAboveEnabled && psParams->bBelowEnabled)
- bAlphaZero = 1; // alpha zero only if both are enabled.
- // else, this shortcut will be exposed badly...
- }
-
- psSrcSample = psParams->psSrcSample;
- psDstSample = psParams->psDstSample;
-
- if (bAlphaZero)
- {
- while (nLength--)
- {
- psDstSample->a = 0;
- psDstSample++;
- }
- }
- else
- {
- while (nLength--)
- {
- psDstSample->r = psSrcSample->r+(((r-psSrcSample->r)*nSrcPercent)>>8);
- psDstSample->g = psSrcSample->g+(((g-psSrcSample->g)*nSrcPercent)>>8);
- psDstSample->b = psSrcSample->b+(((b-psSrcSample->b)*nSrcPercent)>>8);
- psDstSample->a = psSrcSample->a;
- psSrcSample++;
- psDstSample++;
- }
- }
- }
- else
- {
- // calculate the percentage of each of the source frame.
- nSrcPercent = 0;
- if (psParams->dwFrames > 1)
- nSrcPercent = (dwPos*256)/(psParams->dwFrames-1);
-
- if (psParams->bBelow)
- {
- if (psParams->bAboveEnabled)
- nSrcPercent = 256;
- else
- nSrcPercent = 256-nSrcPercent;
- }
-
- psSrcSample = psParams->psSrcSample;
- psDstSample = psParams->psDstSample;
- i = nLength % 8;
- nLength /= 8;
- while (i--)
- {
- psDstSample->r = psSrcSample->r;
- psDstSample->g = psSrcSample->g;
- psDstSample->b = psSrcSample->b;
- psDstSample->a = (psSrcSample->a * nSrcPercent)>>8; // only modify Alpha!
- psSrcSample++;
- psDstSample++;
- }
- while (nLength--)
- {
- unsigned int p1;
- unsigned int *ptr1, *ptr2;
- ptr1 = (unsigned int *)psSrcSample;
- ptr2 = (unsigned int *)psDstSample;
-
- p1 = *(ptr1+0); *(ptr2+0) = p1; *((unsigned char *)(ptr2+0)+3) = ((p1>>24)*nSrcPercent)>>8;
- p1 = *(ptr1+1); *(ptr2+1) = p1; *((unsigned char *)(ptr2+1)+3) = ((p1>>24)*nSrcPercent)>>8;
- p1 = *(ptr1+2); *(ptr2+2) = p1; *((unsigned char *)(ptr2+2)+3) = ((p1>>24)*nSrcPercent)>>8;
- p1 = *(ptr1+3); *(ptr2+3) = p1; *((unsigned char *)(ptr2+3)+3) = ((p1>>24)*nSrcPercent)>>8;
- p1 = *(ptr1+4); *(ptr2+4) = p1; *((unsigned char *)(ptr2+4)+3) = ((p1>>24)*nSrcPercent)>>8;
- p1 = *(ptr1+5); *(ptr2+5) = p1; *((unsigned char *)(ptr2+5)+3) = ((p1>>24)*nSrcPercent)>>8;
- p1 = *(ptr1+6); *(ptr2+6) = p1; *((unsigned char *)(ptr2+6)+3) = ((p1>>24)*nSrcPercent)>>8;
- p1 = *(ptr1+7); *(ptr2+7) = p1; *((unsigned char *)(ptr2+7)+3) = ((p1>>24)*nSrcPercent)>>8;
- psSrcSample += 8;
- psDstSample += 8;
- }
- }
-
- return 0;
- }
-
- int Dissolve(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 255, 255, 0, 0);
- }
-
- int DissolveThroBlack(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 0, 0, 0, 1);
- }
-
- int DissolveThroWhite(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 255, 255, 255, 1);
- }
-
- int DissolveThroRed(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 255, 0, 0, 1);
- }
-
- int DissolveThroGreen(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 0, 255, 0, 1);
- }
-
- int DissolveThroBlue(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 0, 0, 255, 1);
- }
-
- int DissolveThroCyan(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 0, 255, 255, 1);
- }
-
- int DissolveThroMagenta(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 255, 0, 255, 1);
- }
-
- int DissolveThroYellow(HANDLE hStream, ImagePluginApplyParams *psParams)
- {
- return DissolveMain(hStream, psParams, 255, 255, 0, 1);
- }
-
-